<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996  15899929162
// +----------------------------------------------------------------------
namespace app\common\repositories\property\basic;

use app\common\dao\property\basic\PropertyLogDao;
use app\common\repositories\BaseRepository;

/**
 * Class PropertyLogRepository
 *
 * @mixin PropertyLogDao
 */
class PropertyLogRepository extends BaseRepository
{

    public function __construct(PropertyLogDao $dao)
    {
        $this->dao = $dao;
    }

    public function getPropertyList(array $where, $page, $limit, int $propertyId = null)
    {
        $query = $this->dao->search($where,$propertyId);
        $count = $query->count();
        $list = $query->page($page, $limit)
            ->with([
                'userInfo' => function ($query) {
                    $query->field('id,username,nickname');
                    $query->bind(['username' => 'username']);
                }
            ])
            ->order('id', 'desc')
            ->select();
        return compact('list', 'count');
    }
    public function addData(int $propertyId, array $data, int $userId)
    {
        $data['user_id'] = $userId ?? '0';
        $data['property_id'] = $propertyId;
        $data['track_ip'] = app('request')->ip();
        $this->dao->create($data);
    }
}